package com.nicolasprof.profgallery.preloader {
	import com.nicolasprof.profgallery.Engine;
	import com.nicolasprof.profgallery.preloader.Preloader;

	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	/**
	 * @author Nicolas Prof
	 */
	public class TextPreloader extends Preloader {

		private var _textField : TextField;

		public function TextPreloader() {
			super();
		}
		override public function initiate() : void {
			//INIT
			_textField = new TextField();
			var config : XML = Engine.CONFIG_XML;
			var format : TextFormat = new TextFormat(
														config.preloaderText.@font, 
														config.preloaderText.@size, 
														config.preloaderText.@color);

			
			//DISPLAY LIST
			addChild(_textField);
			
			//LISTENERS
			
			//ACTIONS
			_textField.autoSize = TextFieldAutoSize.LEFT;
			_textField.defaultTextFormat = format;
			this.mouseEnabled = false;
			this.mouseChildren = false;
		}

		/**
		 * GETTERS AND SETTERS
		 */
		override public function set progress(ratio : Number) : void {
			_textField.text = ((ratio * 100)>>0) + "%";
			_textField.x = - _textField.width >> 1;
			_textField.y = - _textField.height >> 1;
		}
	}
}
